package org.jeecg.modules.core.util;


import org.springframework.util.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class BimDateUtil {

    public static Date offset(Integer field, Date date, Integer offset){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(field, offset);
        return calendar.getTime();
    }

    public static Date parse(String content, String pattern){
        Date date = null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        try {
            date = simpleDateFormat.parse(content);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static Long strToTime(String strDate,String patten) {
        if (StringUtils.isEmpty(strDate) || StringUtils.isEmpty(patten)) {
            return null;
        }
        SimpleDateFormat formatter = new SimpleDateFormat(patten);
        Date date = null;
        try {
            date = formatter.parse(strDate);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date == null ? null : date.getTime();
    }
}
